package com.chat.controller;

import com.chat.dto.ChatRequest;
import com.chat.service.ChatService;
import com.chat.dto.ChatResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/api/ai")
@CrossOrigin
public class ChatController {

    @Autowired
    private final ChatService chatService;

    public ChatController(ChatService chatService) {
        this.chatService = chatService;
    }

    @PostMapping("/chat")
    public ChatResponse chat(@RequestBody ChatRequest request) {
        return new ChatResponse(
                chatService.chat(request.message()),
                LocalDateTime.now()
        );
    }
}